package cn.kgc.springmvcday03.controller;

import cn.kgc.springmvcday03.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 课工场
 * @date 2023/10/17
 * @description
 */
@Controller
@RequestMapping("user")
public class UserController {


    @RequestMapping("list")
    public ModelAndView  getList(){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("main");
        modelAndView.addObject("info","hello info");

        return  modelAndView;
    }

    @RequestMapping("getById")
    public ModelAndView  getById(Integer id){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("main");
        modelAndView.addObject("info",id);

        return  modelAndView;
    }


    //  ?username= & password= & age=
    // json {"username":"tom","password":"123","age":20}
    @RequestMapping("add")
    public ModelAndView  addOne(@RequestBody User user){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("main");
        modelAndView.addObject("info",user);

        return  modelAndView;
    }
}
